
// imeisn = "868802049323827";
//要查的sn码
var asus=[];

var tmpScCode = getScCode();

console.log("countryId=",countryId);


    //通过门店国家 005 查询集成开关明细，若能查询到则显示 绑定标示和丢失标示字段；若未能查询到 隐藏绑定标示和丢失标示字段 2017/8/3 李文涛
    var fetchXML = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>\
                               <entity name='hw_integratedswitchcountry'>\
                               <attribute name='hw_integratedswitchcountryid' />\
                               <attribute name='hw_name' />\
                               <filter type='and'>\
                               <condition attribute='hw_country' operator='eq'  uitype='hw_country' value='" + countryId + "' />\
                               <condition attribute='statecode' operator='eq' value='0' />\
                               </filter>\
                               <link-entity name='hw_integratedswitch' from='hw_integratedswitchid' to='hw_integratedswitch' alias='aa'>\
                               <filter type='and'>\
                               <condition attribute='hw_switchcode' operator='eq' value='005' />\
                               <condition attribute='statecode' operator='eq' value='0' />\
                               </filter>\
                               </link-entity>\
                               </entity>\
                               </fetch>";
if (countryId != "") {
    CRM.Common.querySync('hw_integratedswitchcountries?fetchXml=' + fetchXML, false, function (ret) {
    }, function (err) { })
}

var startTimestamp=new Date().getTime();
console.log("getMiddleWareDatas");

for (var i = 0; i <imeisnAsus.length; i++) {
    var imeisnTemp=imeisnAsus[i];
    RightInfoUrl = "DeviceRightSync/api/DeviceRight/GetDeviceRightInfoBySNOrIMEI?snimei=" + imeisnTemp + "&langType=" + lcid;
    BaseInfoUrl = "DeviceRightSync/api/DeviceRight/GetDeviceBaseInfoBySNOrIMEI?snimei=" + imeisnTemp + "&langType=" + lcid + "&countryCode=" + countryCode + "&partnerCode=" + scCode + "&filterReturnImei=0";//返回政企客户名称新接口调用 2017/8/2  李文涛
    AntecedentsInfoUrl = "DeviceRightSync/api/DeviceRight/GetDeviceAntecedentsInfoBySNOrIMEI?snimei=" + imeisnTemp + "&langType=" + lcid + "&countryCode=" + countryCode;

    console.log("-----------aaaa,i=",i);
//同步
// 第二个参数为 true 是异步
    //selenium 异步不好搞
    CRM.Common.getMiddleWareDatas(BaseInfoUrl, false, function (result) {
        // console.log("result=",result);
        if (result.ResCode == "000") {
            if (result.ResMessage == "success") {
                var deviceinfo = result.ResBody;
                // console.log("asus="+asus);
                asus.push(deviceinfo);
            } else {
                console.log(result);
                // asus="error";
                asus.push(LanguageResources["custom_rightsearch_getbaseinfofail"] );
            }
        }else{
            asus.push(LanguageResources["custom_rightsearch_getbaseinfofail"] );
        }
    }, function (req) {
        asus.push(LanguageResources["custom_rightsearch_getbaseinfofail"] );
        console.log(req);
    });

}

// function waitAsus() {
//     if (asus.length<imeisnAsus.length){
//         setTimeout(function(){
//             waitAsus();
//             console.log("asus.length=",asus.length,",imeisnAsus.length=",imeisnAsus.length);
//         },100);
//     }
// }

var endTimestamp=new Date().getTime();
console.log("-------------------------------");
// waitAsus();
console.log("time=",(endTimestamp-startTimestamp));
return asus;
